package org.linlinjava.litemall.db.service;

import com.github.pagehelper.PageHelper;
import org.linlinjava.litemall.db.dao.AgedmallUserCashoutMapper;
import org.linlinjava.litemall.db.domain.AgedmallUserCashout;
import org.linlinjava.litemall.db.domain.AgedmallUserCashoutExample;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class AgedmallUserCashoutService {
    @Resource
    private AgedmallUserCashoutMapper agedmallUserCashoutMapper;

    public void add(AgedmallUserCashout agedmallUserCashout) {
        agedmallUserCashout.setAddTime(LocalDateTime.now());
        agedmallUserCashout.setUpdateTime(LocalDateTime.now());
        agedmallUserCashoutMapper.insertSelective(agedmallUserCashout);
    }

    public List<AgedmallUserCashout> list(Integer userId, Integer page, Integer limit) {
        PageHelper.startPage(page, limit);

        AgedmallUserCashoutExample example = new AgedmallUserCashoutExample();
        example.or().andDeletedEqualTo(false)
                .andUserIdEqualTo(userId);
        return agedmallUserCashoutMapper.selectByExample(example);
    }

    public int listCount(Integer userId) {
        AgedmallUserCashoutExample example = new AgedmallUserCashoutExample();
        example.or().andDeletedEqualTo(false)
                .andUserIdEqualTo(userId);
        Long count = agedmallUserCashoutMapper.countByExample(example);
        return count.intValue();
    }
}
